package com.project.server.operate;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.core.page.TableDataInfo;
import com.project.common.enums.BusinessType;
import com.project.common.utils.poi.ExcelUtil;
import com.project.server.domain.operate.TOperateInformation;
import com.project.server.service.operate.ITOperateInformationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 运营管理资讯动态Controller
 *
 * @author project
 * @date 2021-06-29
 */
@RestController
@RequestMapping("/server/information")
public class TOperateInformationController extends BaseController {

    @Resource
    private ITOperateInformationService tOperateInformationService;

    /**
     * 查询运营管理资讯动态列表
     */
    //@PreAuthorize("@ss.hasPermi('server:information:list')")
    @GetMapping("/list")
    public TableDataInfo list(TOperateInformation tOperateInformation) {
        startPage();
        List<TOperateInformation> list = tOperateInformationService.selectTOperateInformationList(tOperateInformation);
        return getDataTable(list);
    }


    /**
     * 导出运营管理资讯动态列表
     */
    @PreAuthorize("@ss.hasPermi('server:information:export')")
    @Log(title = "运营管理资讯动态", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TOperateInformation tOperateInformation) {
        List<TOperateInformation> list = tOperateInformationService.selectTOperateInformationDelTags(tOperateInformation);
        ExcelUtil<TOperateInformation> util = new ExcelUtil<TOperateInformation>(TOperateInformation.class);
        return util.exportExcel(list, "资讯动态列表");
    }

    /**
     * 获取运营管理资讯动态详细信息
     */
    //@PreAuthorize("@ss.hasPermi('server:information:query')")
    @GetMapping(value = "/{informationId}")
    public AjaxResult getInfo(@PathVariable("informationId") Long informationId) {
        return AjaxResult.success(tOperateInformationService.selectTOperateInformationById(informationId));
    }

    /**
     * 新增运营管理资讯动态
     */
    @PreAuthorize("@ss.hasPermi('server:information:add')")
    @Log(title = "运营管理资讯动态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TOperateInformation tOperateInformation) {
        return toAjax(tOperateInformationService.insertTOperateInformation(tOperateInformation));
    }

    /**
     * 修改运营管理资讯动态
     */
    @PreAuthorize("@ss.hasPermi('server:information:edit')")
    @Log(title = "运营管理资讯动态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TOperateInformation tOperateInformation) {
        return toAjax(tOperateInformationService.updateTOperateInformation(tOperateInformation));
    }

    /**
     * 删除运营管理资讯动态
     */
    @PreAuthorize("@ss.hasPermi('server:information:remove')")
    @Log(title = "运营管理资讯动态", businessType = BusinessType.DELETE)
    @DeleteMapping("/{informationIds}")
    public AjaxResult remove(@PathVariable Long[] informationIds) {
        return toAjax(tOperateInformationService.deleteTOperateInformationByIds(informationIds));
    }
}
